package com.solcoo.controller;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;

import com.solcoo.dao.SOBDao;
import com.solcoo.pojo.SOB;
import com.solcoo.pojo.TempList;

public class AbstractController {

	@Resource
	private SOBDao sobDao;
    private static Logger logger = Logger.getLogger(YongHuController.class);

    /**
     * 取得操作错误结果信息
     * @param obj
     * @return
     */
    protected JsonResult getFailJsonResult(String obj) {
        JsonResult result = new JsonResult();
        result.setResult(false);
        result.setFailMsg(obj);
        return result;
    }

    protected JsonResult getFailJsonResult(String obj, String msg) {
        JsonResult result = new JsonResult();
        result.setResult(false);
        result.setMsg(msg);
        result.setFailMsg(obj);
        return result;
    }

    protected JsonResult getFailJsonResult(JsonResult obj) {
        obj.setResult(false);
        return obj;
    }

    /**
     * 取得操作正确结果信息
     * @param obj
     * @return
     */
    protected JsonResult getSuccessJsonResult(String obj) {
        JsonResult result = new JsonResult();
        result.setResult(true);
        result.setMsg(obj);
        return result;
    }

    protected JsonResult getSuccessJsonResult(JsonResult obj) {
        obj.setResult(true);
        return obj;
    }

    protected JsonResult getSuccessJsonResult(List obj, int youbiao) {
        TempList lr = new TempList();
        lr.setResult(true);
        lr.setYoubiao(youbiao);
        lr.setMyList(obj);
        return lr;
    }

    protected JsonResult2 getSuccessJsonResult2(List obj) {
        JsonResult2 result = new JsonResult2();
        result.setMyList(obj);
        result.setResult(true);
        return result;
    }

    protected JsonResult2 getFailJsonResult2() {
        return getFailJsonResult2("操作失败");
    }

    protected JsonResult2 getFailJsonResult2(String msg) {
        JsonResult2 result = new JsonResult2();
        result.setFailMsg(msg);
        result.setResult(false);
        return result;
    }
//
//    protected Boolean checkSOB(String SOB) throws Exception {
//    	if(SOB==null || "".equals(SOB)) {
//    		return false;
//    	}
//    	SOB existSOB = sobDao.getSOB(SOB);
//    	if(existSOB != null) {
//    		return false;
//    	}
//    	if(!("99".equals(SOB.substring(13,15)) && "1".equals(SOB.substring(3, 4)))) {
//    		return false;
//    	}
//    	String sob2 = SOB.substring(0,6) + SOB.substring(7,SOB.length());
//    	StringBuffer sb = new StringBuffer();
//    	sb.append(sob2.substring(12,sob2.length()));
//    	sb.append(sob2.substring(8,12));
//    	sb.append(sob2.substring(4,8));
//    	sb.append(sob2.substring(0,4));
//    	sb.delete(0, 2);
//    	sb.delete(sb.length()-1, sb.length());
//    	Long submitTime = Long.parseLong(sb.toString());
//    	
//    	Long subTime = (System.currentTimeMillis() - submitTime) / 1000;
//
//    	if(subTime<300 && subTime>-300) {
//    		existSOB = new SOB();
//    		existSOB.setShijian(new Date());
//    		existSOB.setSob(SOB);
//    		sobDao.addSOB(existSOB);
//    		return true;
//    	}
//    	
//    	return false;
//    }
}
